//
//  ToutiaoPhotoViewController.m
//  BobNews
//
//  Created by lanou3g on 16/5/6.
//  Copyright © 2016年 liu. All rights reserved.
//

#import "ToutiaoPhotoViewController.h"
#import "NetWorkRequestManager.h"
#import "CycleView.h"
@interface ToutiaoPhotoViewController ()

@property (nonatomic,strong) UIWebView *webView;
@property (nonatomic,strong) CycleView *cycleView;

@property (nonatomic,strong) UIView *contentView;
@property (nonatomic,strong) UILabel *label;

@property (nonatomic,strong) NSString *note;
@end

@implementation ToutiaoPhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    self.title = self.navTitle;
    self.view.backgroundColor = [UIColor blackColor];
    
    self.cycleView = [[CycleView alloc]initWithFrame:CGRectMake(0, 200, self.view.frame.size.width,300) interVal:2];
    [self.view addSubview:self.cycleView];
    
    [self analyticalData];
}
- (void)analyticalData {
    NSString *string =[self.photosetID substringFromIndex:4];
    NSString *string1 = [string stringByReplacingOccurrencesOfString:@"|" withString:@"/"];
    NSString *str = [NSString stringWithFormat:@"http://c.3g.163.com/photo/api/set/%@.json",string1];
    NSLog(@"%@",str);
//    NSString *str = @"http://c.3g.163.com/photo/api/set/0001/117625.json";
    [NetWorkRequestManager requestUrl:[NSURL URLWithString:str] RequestMethod:GET Params:nil Result:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (data) {
//            NSLog(@"%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]);
            NSMutableDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSArray *array = jsonDic[@"photos"];
            
            NSMutableArray *photoArray = [[NSMutableArray alloc]init];
            for (NSDictionary *itemDic in array) {
                NSString *imgurl = itemDic[@"imgurl"];
                [photoArray addObject:imgurl];
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                self.cycleView.imgNameArray = photoArray;
            });
        }
    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
